<template>
	<view class="myFreeInteraction">
		<scroll-view @refresherrefresh="refresherrefresh" @scrolltolower="scrolltolower"
			:refresher-triggered="data.refresherBool" :refresher-enabled="true" scroll-y="true">
			<view class="list">
				<view class="listItem" v-for="(item,index) in data.result.list" :key="index">
					<view class="top">
						<view class="left">
							<image :src="data.httpUrl+'/app/file/viewFile?fileId='+item.publishUserAvatarId"
								mode="aspectFill">
							</image>
							<text class="ellipsis_1">{{item.publishUserName}}</text>
						</view>
						<view class="right">
							<view class="">
								发起了一笔
								<text>{{item.freeAmount}}</text>
								元免单互动
							</view>
							<text>备注:{{item.remark}}</text>
						</view>
					</view>
					<view class="top_1">
						<view class="left" @tap=" handeShare(item)">
							立即分享
						</view>
						<view class="right">
							<view class="item" v-for="(item1,index1) in item.inviteUsers" :key="index1">
								<image :src="data.httpUrl+'/app/file/viewFile?fileId='+item1.userAvatarId"
									mode="aspectFill">
								</image>
								<text>{{item1.percent}}</text>
							</view>
						</view>
					</view>
					<view class="bot">
						活动倒计时
						<view></view>
						<text>{{item.countDownTime}}</text>
					</view>
				</view>
			</view>
		</scroll-view>
		<u-popup :closeOnClickOverlay="false" round="20" mode="center" :show="data.show"
			@close="()=>{data.show = false}">
			<Share :info="{...data.info,freeList:data.freeList}" @close="data.show = false" />
		</u-popup>
	</view>
</template>

<script setup lang="ts">
	import { pageUserFreeOrder } from '@/utils/api/freeShipping'
	import Share from './components/share.vue'
	import { reactive } from 'vue'
	import { onLoad } from '@dcloudio/uni-app';
	import {pageLifeProducts} from '@/utils/api/goods'
	const data = reactive({
		show: false,
		httpUrl: getApp().globalData.baseUrl,
		type: '',
		refresherBool: false,
		result: { list: [],total:0 },
		obj: { queryType: '', pageNo: 1, pageSize: 10, },
		freeList:[],
		info:{}
	})
	const refresherrefresh = () => {
		data.refresherBool = true;
		data.obj.pageNo = 1;
		requstList()
	}
	const handeShare = (item)=>{
		 data.show = true;
		 data.info = item;
		 pageLifeProducts({data:{queryType:'FREE',pageNo:1,pageSize:6,freeCode:item.freeCode}}).then((res)=>{
		 	data.freeList = res.data.list;
		 })
	}
	onLoad(({ type }) => {
		data.obj.queryType = type;
		requstList()
	})

	const requstList = () => {
		uni.showLoading({
			title: '加载中...',
			mask: true
		})
		if (data.obj.pageNo == 1) {
			data.result.list = [];
		}
		pageUserFreeOrder({ data: data.obj }).then((res) => {
			data.refresherBool = false;
			res.data.list = [...data.result.list, ...res.data.pageInfo.list];
			data.result = res.data.pageInfo;
			uni.hideLoading()
		})
	}
	const scrolltolower = () => {
		if (data.result.total != data.result.list.length) {
			data.obj.pageNo += 1;
			requstList()
		}
	}
</script>

<style lang="scss">
	.myFreeInteraction {
		display: flex;
		flex-direction: column;
		height: 100vh;
		background-color: #F6F7F9;

		scroll-view {
			flex: 1;
			padding: 24rpx;
			overflow: auto;
		}

		.list {
			>view:nth-of-type(1) {
				margin-top: 0;
			}

			.listItem {
				margin-top: 20rpx;
				padding: 20rpx;
				border-radius: 24rpx;
				background: #fff;

				>.top {
					display: flex;
					align-items: flex-start;

					.left {
						position: relative;
						width: 120rpx;
						height: 120rpx;
						border-radius: 50%;
						border: 2rpx solid #FF263F;
						margin-right: 32rpx;
						image{
							width: 100%;
							height: 100%;
							border-radius: 50%;
						}
						text {
							// display: inline-block;
							width: 102rpx;
							line-height: 44rpx;
							text-align: center;
							background: #FF263F;
							border-radius: 8rpx;
							font-size: 24rpx;
							color: #fff;
							position: absolute;
							left: 50%;
							bottom: -8rpx;
							margin-left: -51rpx;
						}
					}

					.right {
						flex: 1;

						view {
							font-size: 32rpx;
							margin-bottom: 12rpx;

							text {
								font-size: 32rpx;
								color: #FF263F;
							}
						}

						>text {
							color: #8C8C8C;
						}
					}
				}

				>.top_1 {
					display: flex;
					align-items: flex-end;

					.left {
						width: 125rpx;
						line-height: 44rpx;
						text-align: center;
						border-radius: 22rpx;
						background: linear-gradient(233deg, #FFA34B 0%, #FF8E6F 100%);
						color: #fff;
						font-size: 24rpx;
						margin-right: 27rpx;
					}

					.right {
						display: flex;
						flex: 1;
						flex-wrap: wrap;

						view {
							width: 96rpx;
							height: 96rpx;
							border-radius: 50%;
							border: 2rpx dashed #F0F0F0;
							display: flex;
							align-items: center;
							margin-right: 7rpx;
							justify-content: center;
							color: #8C8C8C;
							font-size: 29rpx;
							font-weight: bold;
							position: relative;
							image{
								width: 100%;
								height: 100%;
								border-radius: 50%;
							}
							text {
								position: absolute;
								right: 0;
								bottom: 0;
								width: 63rpx;
								line-height: 44rpx;
								text-align: center;
								display: inline-block;
								border-radius: 8rpx;
								background: #F4F6FA;
								color: #BFBFBF;
								font-size: 24rpx;
								font-weight: bold;
							}
						}

						>view:last-child {
							margin-right: 0;
						}
					}
				}

				.bot {
					padding-top: 16rpx;
					margin-top: 16rpx;
					border-top: 2rpx solid #F4F6FA;
					display: flex;
					align-items: center;
					color: #8C8C8C;

					view {
						width: 2rpx;
						height: 20rpx;
						background-color: #8C8C8C;
						border-radius: 2rpx;
						margin: 0 10rpx;

					}

					text {
						color: #FF5C60;
					}
				}
			}
		}
	}
</style>